package com.hg.chapter2;

import com.hg.chapter2.profile.MyProfile;
import com.hg.chapter2.profile.MyProfileConfig;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.annotation.AnnotationConfigApplicationContext;
@SpringBootApplication
public class Chapter2Application {

    public static void main(String[] args) {
        //SpringApplication.run(Chapter2Application.class, args);
        AnnotationConfigApplicationContext context=new AnnotationConfigApplicationContext();
        //先设置Environment，再添加配置，否则bean未定义
        context.getEnvironment().setActiveProfiles("prod");
        context.register(MyProfileConfig.class);
        context.refresh();//刷新

        MyProfile bean = context.getBean(MyProfile.class);
        System.out.println(bean.getType());

        context.close();

        //SpringApplication.run(Chapter2Application.class, args);
    }

}
